/**
 * 正式订单维护 - 编辑页面
 * @author sxc
 * @date 2019/01/18
 */
define(function () {

    var self,
        app = win.app,
        doc = document,
        layui = win.layui,
        isPuhuo = false,
        notPuhuo = false,
        vueData = {
            isAdd: false,
            isEdit:false,
            isCheck: false,
            isEnable: false,
            isChange:false,//拆包否控制
            isModify: false,
            form: {GWCS014_NAME: null},
            giftButton:true,//赠品按钮disabled
            rules: {
                GWCSDOCNO: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ],
                GWCSDOCDATE: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ],
                GWCS010: [
                    {required: true, message: '不可为空', trigger: 'change'}
                ],
                GWCS117: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ],
                GWCS118: [
                    {required: true, message: '不可为空', trigger: 'blur'}
                ]
            },
            selectOptions: {
                // crm_gwai710_gwcs117: app.datas_("crm_gwai710_gwcs117")
            },
            selectGwcs117Options:[
            ],
            selectGwcs118Options:[
                {
                    value: 'Y',
                    code: 'Y:是'
                }, {
                    value: 'N',
                    code: 'N:否'
                }
            ]
        },
        cols = [[
            {field: 'GWCSSEQ', type: 'checkbox', title: '选择', totalRowText: '合计'}
            , {field: 'GWCS109', width: 160,title: '活动编号', event: 'openGwdc001' }
            , {field: 'GWDC003', width: 160,title: '活动说明'}
            , {field: 'GWCS001', width: 100,title: '产品编号', event: 'openGwda003'}
            , {field: 'GWAML003',width: 160,title: '品名'}
            , {field: 'GWAML004',width: 160,title: '规格'}
            , {field: 'GWCS003', width: 80,title: '数量', edit: 'text'}
            , {field: 'GWCS112', width: 100,title: '仓库类型',filterDatas: app.datas_('crm_gwai710_gwcs112')}
            , {field: 'GWCS113', width: 80,title: '发货仓库',event:'openCangKu'}
            , {field: 'GWCS002', width: 80,title: '销售单位'}
            , {field: 'GWCS004', width: 80,title: '单价'}
            , {field: 'GWCS032', width: 80, title: '税种',event:'openShuizhong'}
            , {field: 'GWEA006', width: 80, title: '税率'}
            , {field: 'GWCS040', width: 80, title: '税额'}
            , {field: 'GWCS005', width: 80, title: '含税金额', totalRow: true}
            //, {field: 'GWCS016', width: 120, title: '预计交货日期', edit: 'date'}
            , {field: 'GWCS110', width: 80, title: '促销方式',
                filterDatas: app.datas_('crm_gwdc_gwdc005'),search: 'default',
                searchOpts: {type: 'select', default: ''}
                }
            , {field: 'GWCS111', title: '促销单据类型', hide: true}
            , {field: 'GWCS033', title: '汇率种类', filterDatas: app.datas_('gwai710_gwcs033'), hide: true}
            , {field: 'GWCS034', title: '汇率', edit: 'text', hide: true}
            , {field: 'GWCS036', title: '原币含税折后价', edit: 'text', hide: true}
            , {field: 'GWCS037', title: '本币单价', edit: 'text', hide: true}
            , {field: 'GWCS038', title: '本币含税金额', edit: 'text', hide: true}
            , {field: 'GWCS039', title: '本币含税折扣价', edit: 'text', hide: true}
            , {field: 'GWCS041', title: '本币税额', edit: 'text', hide: true}
            , {field: 'GWCSMLEGAL', title: '法人组织', hide: true}
            , {field: 'GWCSPLANT', title: '归属ERP法人组织', hide: true}
            // , {field: 'GWCS035', title: '折扣率', hide: true}
            , {field: 'GWCS043', title: '购物车单号', hide: true}
            , {field: 'GWCS101', title: '购物车相序', hide: true}
            , {field: 'GWDC020', title: '起订数量', hide: true}
            , {field: 'GWDC021', title: '起订金额', hide: true}
            , {field: 'GWCS115', title: '结算价', hide: true}
            , {field: 'GWCS116', title: '标准结算价上浮%', hide: true}
        ]],
        callObj,
        moduleName,
        listData = null,
        table, gwai710Table, layOpenIndex,pageVue
    ;

    var Gwai710Edit = app.Module.extend({
            init: function () {
                self = this;
                self._super({
                    _tag: 'gwai710_edit',
                    _loadTplsFull: [{
                        dom: 'common_open_window', tpl: 'common/_open_window' //0
                    },{
                        dom: 'common_open_gwdc001', tpl: 'common/_open_gwdc001' //1
                    },{
                        dom: 'gwai710_edit_giftInfo', tpl: 'gwai710_edit_giftInfo' //2
                    }
                    ]
                }, win);
            },
            initTable: function () {
                layui.use(['table'], function () {
                    table = layui.table;
                    gwai710Table = table.render({
                        elem: app.getByid(doc, 'gwai710_edit_table'),
                        // url: g_ctxPath + 'crm/gwai710/listGwcs',
                        cellMinWidth: 80,
                        id: 'gwai710_edit_table',
                        //toolbar: '#gift-table-toolbar',
                        defaultToolbar:false,
                        cols: cols,
                        data: listData,
                        page: false,
                        totalRow: true
                    });
                    table.on('tool(gwai710_edit_table)', function (obj) {
                        if (obj.event === 'openGwdc001'){
                            self._openTplFull({
                                tag: 'common_open_window',
                                tagData: {
                                    config: {
                                        method:'q_gwdc001',
                                        columnList: [
                                            {label: '活动编号', prop: 'GWDC001', width: '150'},
                                            {label: '活动说明', prop: 'GWDC003', width: '150'},
                                            {label: '促销方式', prop: 'GWDC005', width: '150'},
                                            {label: '促销单据类型', prop: 'GWDC004', width: '150'},
                                            {label: '生效日期', prop: 'GWDC009', width: '150'}
                                        ],
                                        searchParam:{
                                            GWCS010:vueData.form.GWCS010, //经销商
                                            GWCS117:vueData.form.GWCS117,//订单类型
                                            GWCSDOCDATE:vueData.form.GWCSDOCDATE,//单据日期
                                        }
                                    },
                                    cb: function (data) {
                                        if(data.GWDC004 == '1:组合'){
                                            data.GWDC004='1';
                                        }else if(data.GWDC004 == '2:非组合'){
                                            data.GWDC004='2';
                                        }else{
                                            data.GWDC004='';
                                        }
                                        if(data.GWDC005 == '1:裸价'){
                                            data.GWDC005='1';
                                        }else if(data.GWDC005 == '2:特价'){
                                            data.GWDC005='2';
                                        }else if(data.GWDC005 == '3:满额赠送'){
                                            data.GWDC005='3';
                                        }else if(data.GWDC005 == '4:满量赠送'){
                                            data.GWDC005='4';
                                        }else{
                                            data.GWDC005='';
                                        }

                                        obj.update({
                                            'GWCS109': data.GWDC001,
                                            'GWDC003': data.GWDC003,
                                            'GWCS110': data.GWDC005,
                                            'GWCS111': data.GWDC004,
                                            GWCS001: '',
                                            GWAML003: '',
                                            GWAML004: '',
                                            // GWCS112: obj.data.GWCS112,
                                            GWCS112: '',
                                            GWCS116: '',
                                            GWCS113:'',
                                            GWCS003: '0',
                                            GWCS002: '',
                                            GWCS004: '',
                                            // GWCS032: '',
                                            GWCS040: 0,
                                            GWCS005: 0,
                                            // GWCS016: '',
                                            GWCS033: '2',
                                            GWCS034: vueData.form.GWCS034,
                                            GWCS036: 0,
                                            GWCS037: 0,
                                            GWCS038: 0,
                                            GWCS039: 0,
                                            GWCS041: 0,
                                            GWCSMLEGAL: vueData.form.GWCSMLEGAL,
                                            GWCSPLANT: vueData.form.GWCSPLANT,
                                            GWEA006: '',
                                            GWCS035: 1,
                                            GWCS043: '',
                                            GWCS101: ''
                                        });
                                    }
                                },
                                index: 0,
                                openOpts: {
                                    title: '选择活动信息',
                                    area: ['600px', '500px']
                                }
                            });
                        }else if (obj.event === 'openGwda003'){
                            var list = gwai710Table.getDatas();
                            var keyArray=[];
                            for(var i =0;i<list.length;i++){
                                keyArray.push(
                                    list[i]['GWCS001']
                                );
                            }
                            var keyArrayStr=keyArray.join(',');
                            self._openTplFull({
                                tag: 'common_open_window',
                                tagData: {
                                    multiple:true,
                                    config: {
                                        method:'cq_gwam001_3',
                                        columnList: [
                                            {label: '产品编号', prop: 'GWDA003', width: '150'},
                                            {label: '品名', prop: 'GWAML003', width: '150'},
                                            {label: '规格', prop: 'GWAML004', width: '150'},
                                            {label: '单位', prop: 'GWAM008', width: '150'}
                                        ],
                                        dataList:[],
                                        key:'GWDA003',
                                        searchParam:{
                                            GWCS010:vueData.form.GWCS010, //经销商
                                            GWDC001:obj.data.GWCS109, //活动编号
                                            GWCSDOCDATE:vueData.form.GWCSDOCDATE,//单据日期
                                            keyArrayStr:keyArrayStr
                                        }
                                    },
                                    cb: function (data) {
                                        listData = gwai710Table.getDatas();
                                        var select = [];
                                        var _xdata = [];
                                        for (var i = 0; i < data.length; i++) {
                                            _xdata.push({
                                                GWCSDOCDATE:vueData.form.GWCSDOCDATE,
                                                GWCS010:vueData.form.GWCS010,
                                                GWCS001:data[i].GWDA003,
                                                GWCS109:obj.data.GWCS109,
                                                GWCS118:vueData.form.GWCS118
                                            })
                                        }
                                        if(!app.isEmpty(_xdata)){
                                            app.ajax({
                                                xurl: 'crm/gwai710/getPrice',
                                                xdata: _xdata,
                                                toJsonStr: true,
                                                cb: function (rt) {
                                                    if (rt.ok) {
                                                        for (var i = 0; i < rt.data.data.length; i++) {
                                                            var hs=math.mul(rt.data.data[i].GWDC020,rt.data.data[i].GWDC024);
                                                            select.push({
                                                                'GWCSSEQ': listData.length + i,
                                                                'GWCS109': obj.data.GWCS109,
                                                                'GWDC003': obj.data.GWDC003,
                                                                'GWCS001': rt.data.data[i].GWDC018,
                                                                'GWAML003': rt.data.data[i].GWAML003,
                                                                'GWAML004': rt.data.data[i].GWAML004,
                                                                // 'GWCS112': obj.data.GWCS112,
                                                                'GWCS112': rt.data.data[i].GWCS112,
                                                                'GWCS116': obj.data.GWCS116,
                                                                'GWCS113': rt.data.data[i].GWCS113,
                                                                'GWCS003': rt.data.data[i].GWDC020,
                                                                'GWCS002':rt.data.data[i].GWDC019,
                                                                'GWCS004':rt.data.data[i].GWDC024,
                                                                'GWCS115':rt.data.data[i].GWDC023,
                                                                'GWCS032':rt.data.data[i].GWCS032,
                                                                'GWCS035':rt.data.data[i].GWCS035,
                                                                'GWCS040':math.sub(hs,math.div(hs,math.add(1,math.div(rt.data.data[i].GWCS032_,100)))).toFixed(2),
                                                                'GWCS041':math.sub(hs,math.div(hs,math.add(1,math.div(rt.data.data[i].GWCS032_,100)))).toFixed(2),
                                                                'GWCS005':math.mul(rt.data.data[i].GWDC020,rt.data.data[i].GWDC024),
                                                                // 'GWCS016':vueData.form.GWCSDOCDATE,
                                                                'GWCS110':rt.data.data[i].GWCS110,
                                                                'GWCS111':obj.data.GWCS111,
                                                                'GWEA006':rt.data.data[i].GWCS032_,
                                                                'GWDC020':rt.data.data[i].GWDC020,
                                                                'GWDC021':rt.data.data[i].GWDC021

                                                            })
                                                        }
                                                        var unselect = [];
                                                        var arr1 = [];
                                                        var arr2 = [];
                                                        select.forEach(function (v) {
                                                            arr1.push(v.GWCS001);
                                                        });
                                                        _xdata.forEach(function (v) {
                                                            arr2.push(v.GWCS001);
                                                        });
                                                        arr1.concat(arr2).filter(function (item) {
                                                            if (!arr1.includes(item) || !arr2.includes(item)) {
                                                                unselect.push(item);
                                                            }
                                                        });
                                                        if (select.length > 0) {
                                                            listData.removeByMap({
                                                                GWCSSEQ: obj.data.GWCSSEQ
                                                            });
                                                            listData.push.apply(listData, select);
                                                        }
                                                        self.tableReload();
                                                        if (select.length != _xdata.length) {
                                                            var text = '';
                                                            unselect.forEach(function (v) {
                                                                text = text + v + ',';
                                                            });
                                                            app.showWarning('选择的商品' + text + '未设置结算价或结算价未审核请检查!');
                                                        }
                                                    }
                                                }
                                            });

                                        }
                                    }
                                },
                                index: 0,
                                openOpts: {
                                    title: '选择产品信息',
                                    area: ['600px', '500px']
                                }
                            });
                        }else if (obj.event === 'openCangKu'){
                            self._openTplFull({
                                tag: 'common_open_window',
                                tagData: {
                                    config: {
                                        method:'q_gwas001',
                                        columnList: [
                                            {label: '仓库编号', prop: 'GWAS001', width: '150'},
                                            {label: '仓库名称', prop: 'GWASL003', width: '150'}
                                        ]
                                    },
                                    cb: function (data) {
                                        // vueData.form.GWAM019_NAME = data.GWASL003;
                                        // vueData.form.GWAM019 = data.GWAS001;
                                        obj.update({
                                            'GWCS113': data.GWAS001,
                                            'GWCS112': data.GWAS003
                                        });
                                    },
                                },
                                index: 0,
                                openOpts: {
                                    title: '选择仓库信息',
                                    area: ['600px', '470px']
                                }
                            });

                        }else if (obj.event === 'openShuizhong'){
                            self._openTplFull({
                                tag: 'common_open_window',
                                tagData: {
                                    config: {
                                        method:'q_gwea001',
                                        columnList: [
                                            {label: '税种编号', prop: 'GWEA001', width: '150'},
                                            {label: '税种名称', prop: 'GWEA002', width: '150'}
                                        ]
                                    },
                                    cb: function (data) {
                                        obj.update({
                                            'GWCS032': data.GWEA001,
                                            'GWEA006':data.GWEA006,
                                        });
                                        if(obj.data.GWCS003 >0){
                                            var hs=math.mul(obj.data.GWCS003,obj.data.GWCS004);
                                            obj.update({
                                                'GWCS040': math.sub(hs,math.div(hs,math.add(1,math.div(data.GWEA006,100)))).toFixed(2),
                                                'GWCS005':hs
                                            });
                                        }
                                    },
                                },
                                index: 0,
                                openOpts: {
                                    title: '选择税种',
                                    area: ['600px', '470px']
                                }
                            });

                        }
                    });
                    //监听单元格编辑
                    table.on('edit(gwai710_edit_table)', function (obj) {
                        if (obj.field == 'GWCS001') {

                        }else if (obj.field == 'GWCS003') {
                            // listData=gwai710Table.getDatas();
                            if(obj.data.GWCS109==null || obj.data.GWCS109==""){
                                if(obj.value <=0){
                                    layer.msg('数量不可小于等于0');
                                }else {
                                    var hs=math.mul(obj.value,obj.data.GWCS115);
                                    obj.updateOfEdit({
                                        'GWCS003':obj.value,
                                        'GWCS004':obj.data.GWCS004,
                                        'GWCS040':math.sub(hs,math.div(hs,math.add(1,math.div(obj.data.GWEA006,100)))).toFixed(2),
                                        'GWCS005':math.mul(obj.value,obj.data.GWCS004)
                                    });
                                    listData=gwai710Table.getDatas();
                                    self.tableReload();
                                }

                            }
                            //组合+满额赠送
                            if(obj.data.GWCS109!=null && obj.data.GWCS111 =="1" && obj.data.GWCS110=="3"){
                                // self.checkGwdc021(obj);
                                    var hs=math.mul(obj.value,obj.data.GWCS004);
                                    obj.updateOfEdit({
                                        'GWCS003':obj.value,
                                        'GWCS004':obj.data.GWCS004,
                                        'GWCS040':math.sub(hs,math.div(hs,math.add(1,math.div(obj.data.GWEA006,100)))).toFixed(2),
                                        'GWCS005':math.mul(obj.value,obj.data.GWCS004)
                                    });
                                    listData=gwai710Table.getDatas();
                                    self.tableReload();


                            }
                            //组合+满量赠送
                            if(obj.data.GWCS109!=null && obj.data.GWCS111 =="1" && obj.data.GWCS110=="4"){
                                // self.checkGwdc020(obj);
                                var hs=math.mul(obj.value,obj.data.GWCS004);
                                obj.updateOfEdit({
                                    'GWCS003':obj.value,
                                    'GWCS004':obj.data.GWCS004,
                                    'GWCS040':math.sub(hs,math.div(hs,math.add(1,math.div(obj.data.GWEA006,100)))).toFixed(2),
                                    'GWCS005':math.mul(obj.value,obj.data.GWCS004)
                                });
                                listData=gwai710Table.getDatas();
                                self.tableReload();
                            }
                            //非组合+满额赠送
                            if(obj.data.GWCS109!=null && obj.data.GWCS111 =="2" && obj.data.GWCS110=="3"){
                                // self.checkGwdc021(obj);
                                var _yData={
                                    GWCSDOCDATE:vueData.form.GWCSDOCDATE,
                                    GWCS010:vueData.form.GWCS010,
                                    GWCS001:obj.data.GWCS001,
                                    GWCS109:obj.data.GWCS109,
                                    GWCS003:obj.value,
                                    GWCS115:obj.data.GWCS115 //结算价
                                };
                                app.ajax({
                                    xurl: 'crm/gwai710/getPriceSingel',
                                    xdata: _yData,
                                    async:false,
                                    cb: function (rtt) {
                                        if (rtt.ok) {
                                            if((rtt.data.data.GWDC024 !=null ||rtt.data.data.GWDC024 !="") && rtt.data.data !=""){
                                                var hs=math.mul(obj.value,rtt.data.data.GWDC024);
                                                obj.updateOfEdit({
                                                    'GWCS003':obj.value,
                                                    'GWCS004':rtt.data.data.GWDC024,
                                                    'GWCS040':math.sub(hs,math.div(hs,math.add(1,math.div(obj.data.GWEA006,100)))).toFixed(2),
                                                    'GWCS005':math.mul(obj.value,rtt.data.data.GWDC024)
                                                });
                                            }else {
                                                var hs=math.mul(obj.value,obj.data.GWCS115);
                                                obj.updateOfEdit({
                                                    'GWCS003':obj.value,
                                                    'GWCS004':obj.data.GWCS115,
                                                    'GWCS040':math.sub(hs,math.div(hs,math.add(1,math.div(obj.data.GWEA006,100)))).toFixed(2),
                                                    'GWCS005':math.mul(obj.value,obj.data.GWCS115)
                                                });
                                            }
                                        }
                                    }
                                });
                                /*var hs=math.mul(obj.value,obj.data.GWCS004);
                                obj.updateOfEdit({
                                    'GWCS003':obj.value,
                                    'GWCS004':obj.data.GWCS004,
                                    'GWCS040':math.sub(hs,math.div(hs,math.add(1,math.div(obj.data.GWEA006,100)))).toFixed(2),
                                    'GWCS005':math.mul(obj.value,obj.data.GWCS004)
                                });*/
                                listData=gwai710Table.getDatas();
                                self.tableReload();
                            }
                            //非组合+满量赠送
                            if(obj.data.GWCS109!=null && obj.data.GWCS111 =="2" && obj.data.GWCS110 =="4"){
                                // self.checkGwdc020(obj);
                                var _yData={
                                    GWCSDOCDATE:vueData.form.GWCSDOCDATE,
                                    GWCS010:vueData.form.GWCS010,
                                    GWCS001:obj.data.GWCS001,
                                    GWCS109:obj.data.GWCS109,
                                    GWCS003:obj.value
                                };
                                app.ajax({
                                    xurl: 'crm/gwai710/getPriceSingel',
                                    xdata: _yData,
                                    async:false,
                                    cb: function (rtt) {
                                        if (rtt.ok) {
                                            if((rtt.data.data.GWDC024 !=null ||rtt.data.data.GWDC024 !="") && rtt.data.data !=""){
                                                var hs=math.mul(obj.value,rtt.data.data.GWDC024);
                                                obj.updateOfEdit({
                                                    'GWCS003':obj.value,
                                                    'GWCS004':rtt.data.data.GWDC024,
                                                    'GWCS040':math.sub(hs,math.div(hs,math.add(1,math.div(obj.data.GWEA006,100)))).toFixed(2),
                                                    'GWCS005':math.mul(obj.value,rtt.data.data.GWDC024)
                                                });
                                            }else {
                                                var hs=math.mul(obj.value,obj.data.GWCS115);
                                                obj.updateOfEdit({
                                                    'GWCS003':obj.value,
                                                    'GWCS004':obj.data.GWCS115,
                                                    'GWCS040':math.sub(hs,math.div(hs,math.add(1,math.div(obj.data.GWEA006,100)))).toFixed(2),
                                                    'GWCS005':math.mul(obj.value,obj.data.GWCS115)
                                                });
                                            }
                                        }
                                    }
                                });
                                /*var hs=math.mul(obj.value,obj.data.GWCS004);
                                obj.updateOfEdit({
                                    'GWCS003':obj.value,
                                    'GWCS004':obj.data.GWCS004,
                                    'GWCS040':math.sub(hs,math.div(hs,math.add(1,math.div(obj.data.GWEA006,100)))).toFixed(2),
                                    'GWCS005':math.mul(obj.value,obj.data.GWCS004)
                                });*/
                                listData=gwai710Table.getDatas();
                                self.tableReload();
                            }
                            //组合|非组合+裸价、特价
                            if(obj.data.GWCS109!=null && (obj.data.GWCS111 =="1" || obj.data.GWCS111 =="2") && obj.data.GWCS110!="3" && obj.data.GWCS110!="4"){
                                var GWDC020=0,
                                    GWDC021=0;
                                var _xData={};
                                if(obj.data.GWCS111 =="1"){
                                    _xData={GWCS109:obj.data.GWCS109,GWCS010:vueData.form.GWCS010};
                                }else {
                                    _xData={GWCS109:obj.data.GWCS109,GWCS001:obj.data.GWCS001,GWCS010:vueData.form.GWCS010}
                                }
                                if(obj.data.GWCS110=="2"){
                                    _xData.GWDC005=obj.data.GWCS110;
                                }
                                app.ajax({
                                    xurl: 'crm/gwai710/getGwdc020_021',
                                    xdata: _xData,
                                    async:false,
                                    cb: function (rt) {
                                        if (rt.ok) {
                                            GWDC020=rt.data.data.GWDC020;
                                            GWDC021=rt.data.data.GWDC021;
                                            var GWCS003=0;
                                            if(obj.data.GWCS111 =="1"){//组合
                                                listData.forEach(function (item) {
                                                    if(item.GWCS109==obj.data.GWCS109 && item.GWCSSEQ !=obj.data.GWCSSEQ){
                                                        GWCS003=math.add(GWCS003,item.GWCS003);
                                                    }
                                                })
                                                GWCS003=math.add(GWCS003,obj.value);
                                            }else{
                                                if(rt.data.data.GWDC022 =="Y"){//阶梯定价
                                                    _xData.GWCS003=obj.value;
                                                    _xData.GWCS001=obj.data.GWCS001;
                                                    _xData.GWCS010=obj.data.GWCS010;
                                                    _xData.GWCSDOCDATE=obj.data.GWCSDOCDATE;
                                                    app.ajax({
                                                        xurl: 'crm/gwai710/getGwdc020_021_jieti',
                                                        xdata: _xData,
                                                        async:false,
                                                        cb: function (rtt) {
                                                            if((rtt.data.data.GWDC024 !=null ||rtt.data.data.GWDC024 !="") && rtt.data.data !=""){
                                                                var hs=math.mul(obj.value,rtt.data.data.GWDC024);
                                                                obj.updateOfEdit({
                                                                    'GWCS003':obj.value,
                                                                    'GWCS004':rtt.data.data.GWDC024,
                                                                    'GWCS040':math.sub(hs,math.div(hs,math.add(1,math.div(obj.data.GWEA006,100)))).toFixed(2),
                                                                    'GWCS005':math.mul(obj.value,rtt.data.data.GWDC024)
                                                                });
                                                            }else {
                                                                var hs=math.mul(obj.value,obj.data.GWCS115);
                                                                obj.updateOfEdit({
                                                                    'GWCS003':obj.value,
                                                                    'GWCS004':obj.data.GWCS115,
                                                                    'GWCS040':math.sub(hs,math.div(hs,math.add(1,math.div(obj.data.GWEA006,100)))).toFixed(2),
                                                                    'GWCS005':math.mul(obj.value,obj.data.GWCS115)
                                                                });
                                                            }
                                                            // listData=gwai710Table.getDatas();
                                                            // self.tableReload();
                                                        }
                                                    });
                                                }
                                                GWCS003=obj.value;
                                            }
                                            if(GWCS003 < GWDC020){
                                                app.confirm({
                                                    msg: '修改数量导致不满足促销活动，是否确定修改？',
                                                    ok: function () {
                                                        var hs=math.mul(obj.value,obj.data.GWCS115);
                                                        //先调整当前行
                                                        listData[obj.index].GWCS003=obj.value;
                                                        listData[obj.index].GWCS109='';
                                                        listData[obj.index].GWDC003='';
                                                        listData[obj.index].GWCS110='';
                                                        listData[obj.index].GWCS111='';
                                                        listData[obj.index].GWCS004=obj.data.GWCS115;
                                                        listData[obj.index].GWCS040=math.sub(hs,math.div(hs,math.add(1,math.div(obj.data.GWEA006,100)))).toFixed(2);
                                                        listData[obj.index].GWCS005=math.mul(obj.value,obj.data.GWCS115);
                                                        /*obj.updateOfEdit({
                                                            'GWCS003':obj.value,
                                                            'GWCS109': '',
                                                            'GWDC003': '',
                                                            'GWCS110': '',
                                                            'GWCS111': '',
                                                            'GWCS004':obj.data.GWCS115,
                                                            'GWCS040':math.sub(hs,math.div(hs,math.add(1,math.div(obj.data.GWEA006,100)))).toFixed(2),
                                                            'GWCS005':math.mul(obj.value,obj.data.GWCS115)
                                                        });*/
                                                        if(obj.data.GWCS111=="1"){//组合
                                                            //再调整其他行
                                                            for(i=0;i<listData.length;i++){
                                                                if(obj.data.GWCS109==listData[i].GWCS109){
                                                                    listData[i].GWCS109='';
                                                                    listData[i].GWDC003='';
                                                                    listData[i].GWCS110='';
                                                                    listData[i].GWCS111='';
                                                                    listData[i].GWCS004=listData[i].GWCS115;
                                                                    listData[i].GWCS005=math.mul(listData[i].GWCS003,listData[i].GWCS115);
                                                                    listData[i].GWCS040=math.sub(listData[i].GWCS005,math.div(listData[i].GWCS005,math.add(1,math.div(listData[i].GWEA006,100)))).toFixed(2);
                                                                }
                                                            }
                                                        }
                                                        // listData=gwai710Table.getDatas();
                                                        self.tableReload();
                                                    },
                                                    cancel:function () {
                                                        obj.value=listData[obj.index].GWCS003;
                                                        obj.updateOfEdit({
                                                            'GWCS003':GWDC020,
                                                            'GWCS004':obj.data.GWCS004,
                                                            'GWCS040':obj.data.GWCS040,
                                                            'GWCS005':obj.data.GWCS005
                                                        });
                                                        self.tableReload();
                                                    }
                                                });
                                            }else {
                                                // edit by 20190521
                                                /*var hs=math.mul(obj.value,obj.data.GWCS004);
                                                obj.updateOfEdit({
                                                    'GWCS003':obj.value,
                                                    'GWCS004':obj.data.GWCS004,
                                                    'GWCS040':math.sub(hs,math.div(hs,math.add(1,math.div(obj.data.GWEA006,100)))).toFixed(2),
                                                    'GWCS005':math.mul(obj.value,obj.data.GWCS004)
                                                });*/
                                                listData=gwai710Table.getDatas();
                                                self.tableReload();
                                            }
                                        }
                                    }
                                });

                            }
                            gwai710Table.reload( {
                                data: table.cache.test, totalRow: true, toolbar: true
                            });
                        } else if (obj.field == 'GWCS112') {
                            if(obj.value=="2" && obj.data.GWCS112=="1"){
                                var GWCS112="",
                                    GWCS116=0;
                                app.ajax({
                                    xurl: 'crm/gwai710/getGwdd',
                                    xdata: {GWCS010: vueData.form.GWCS010,GWCSDOCDATE:vueData.form.GWCSDOCDATE},
                                    cb: function (result) {
                                        if(result.data.data.GWDD003=="2"){
                                            GWCS112="2";
                                            GWCS116=result.data.data.GWDD013;
                                        }else {
                                            GWCS112="1";
                                            GWCS116=0;
                                        }
                                    }
                                });
                                obj.update({
                                    'GWCS112': obj.value,
                                    'GWCS116':GWCS116
                                });
                                gwai710Table.reload({
                                    data: table.cache.test, totalRow: true, toolbar: true
                                });
                            }
                            if(obj.value=="1" && obj.data.GWCS112=="2"){
                                obj.updateOfEdit({
                                    'GWCS112': obj.value,
                                    'GWCS116':0
                                });
                                gwai710Table.reload({
                                    data: table.cache.test, totalRow: true, toolbar: true
                                });
                            }
                        }
                    });
                });
            },
            tableReload: function () {
                gwai710Table.reload( {
                    data: listData
                });
            },
            addData: function (listData) {
                app.ajax({
                    xurl: 'crm/gwai710/addData',
                    xdata: listData,
                    toJsonStr: true,
                    okmsg: '正式订单增加成功',
                    cb: function (result) {
                        if (result.ok) {
                            app.pageModule('gwai710').reloadTableCurr();
                            vueData.isAdd = true;
                            vueData.isCheck = true;
                            listData = gwai710Table.getDatas();
                            vueData.giftButton = true;
                            listData.forEach(function (item) {
                                if(item.GWCS110=="3" || item.GWCS110=="4"){
                                    vueData.giftButton = false;
                                    return;
                                }
                            })
                            // layer.close(layOpenIndex);
                        }
                    }
                });
            },
            editData: function (listData) {
                app.ajax({
                    xurl: 'crm/gwai710/editData',
                    xdata: listData,
                    toJsonStr: true,
                    okmsg: '正式订单修改成功',
                    cb: function (result) {
                        if (result.ok) {
                            app.pageModule('gwai710').reloadTableCurr();
                            vueData.isAdd = true;
                            vueData.isCheck = true;
                            listData = gwai710Table.getDatas();
                            vueData.giftButton = true;
                            listData.forEach(function (item) {
                                if(item.GWCS110=="3" || item.GWCS110=="4"){
                                    vueData.giftButton = false;
                                    return;
                                }
                            })
                            // layer.close(layOpenIndex);
                        }
                    }
                });
            },
            deleteDataBatch: function () {
                var checkStatus = table.checkStatus('gwai710_edit_table');
                if (checkStatus.data.length > 0) {
                    var _xdata = [];
                    checkStatus.data.forEach(function (v) {
                        var _temp = app.fields_('base_gwai700');
                        _temp.GWCQENT = v.GWCQENT;
                        _temp.GWCQDOCNO = v.GWCQDOCNO;
                        _temp.GWCQSEQ = v.GWCQSEQ;
                        _xdata.push(_temp);
                    });
                    app.ajax({
                        xurl: 'base/gwai700/deleteDataBatch',
                        xdata: _xdata,
                        toJsonStr: true,
                        okmsg: moduleName + '信息删除成功',
                        cb: function (result) {
                            if (result.ok) {
                                self.tableReload();
                            }
                        }
                    });
                }
            },
            _call: function (tagData) {
                pageVue.$refs['form'].resetFields();
                moduleName = tagData.moduleName;
                layOpenIndex = tagData.layOpenIndex;
                isPuhuo=tagData.isPuhuo;
                notPuhuo=tagData.notPuhuo;
                vueData.selectGwcs117Options=[
                    {code: '1', value: '1.现款有返利',disabled:notPuhuo},
                    {code: '2', value: '2.现款无返利',disabled:notPuhuo},
                    {code: '3', value: '3.账期有返利',disabled:notPuhuo},
                    {code: '4', value: '4.账期无返利',disabled:notPuhuo},
                    {code: '5', value: '5.铺货有返利',disabled:isPuhuo},
                    {code: '6', value: '6.铺货无返利',disabled:isPuhuo}
                ];
                if (tagData.is_check) {
                    vueData.isCheck = true;
                } else {
                    vueData.isCheck = false;
                }
                if (tagData.is_add) {
                    vueData.isAdd = true;
                    vueData.giftButton = true;
                    vueData.isEnable = false;
                    app.ajax({
                        xurl: 'crm/gwai710/getGwcsdocno',
                        cb: function (result) {
                            if (result.ok) {
                                app.extendUpLow({
                                    target: vueData.form,
                                    res: {
                                        GWCSDOCNO: result.data.data.GWCQDOCNO,
                                        GWCSDOCDATE: result.data.data.GWCQDOCDATE,
                                        GWCS014: result.data.data.GWCS014,
                                        GWCS014_NAME: result.data.data.GWCS014_NAME,
                                        GWCS118:"N"
                                    },
                                    reset: true
                                });
                                if( typeof(result.data.data.GWCS010) !== "undefined"){
                                    vueData.form.GWCS010=result.data.data.GWCS010;
                                    vueData.form.GWAKL003=result.data.data.GWCS010_NAME;
                                }
                                if(notPuhuo){
                                    vueData.form.GWCS119='2'
                                }else {
                                    vueData.form.GWCS119='1'
                                }
                                listData = [];
                                self.tableReload();
                            }
                        }
                    });
                } else {
                    vueData.isAdd = false;
                    vueData.isEdit = tagData.is_eidt;
                    vueData.isCheck = tagData.is_check;
                    vueData.isModify = tagData.is_modify;

                    callObj = tagData.obj;
                    app.extendUpLow({
                        target: vueData.form,
                        res: callObj.data,
                        reset: true
                    });
                    if(vueData.form.GWCS119=="2"){
                        isPuhuo=false;
                        notPuhuo=true;
                    }else {
                        isPuhuo=true;
                        notPuhuo=false;
                    }
                    vueData.selectGwcs117Options=[
                        {code: '1', value: '1.现款有返利',disabled:notPuhuo},
                        {code: '2', value: '2.现款无返利',disabled:notPuhuo},
                        {code: '3', value: '3.账期有返利',disabled:notPuhuo},
                        {code: '4', value: '4.账期无返利',disabled:notPuhuo},
                        {code: '5', value: '5.铺货有返利',disabled:isPuhuo},
                        {code: '6', value: '6.铺货无返利',disabled:isPuhuo}
                    ];
                    app.ajax({
                        xurl: 'crm/gwai710/listGwcs',
                        xdata: {GWCSDOCNO: callObj.data.GWCSDOCNO},
                        async:false,
                        cb: function (result) {
                            listData = result.data.data;
                            self.tableReload();
                            vueData.giftButton = true;
                            listData.forEach(function (item) {
                                if(item.GWCS110=="3" || item.GWCS110=="4"){
                                    vueData.giftButton = false;
                                    return;
                                }
                            })
                            if(listData.length > 0){
                                vueData.isEnable = true;
                            }
                        }
                    });
                    if(vueData.isEdit){
                        vueData.giftButton = true;
                    }
                }

            },
            _ready: function () {
                table = layui.table;
                vueData.form = app.fields_(['GWCS'],vueData.form);
                pageVue = new Vue({
                    el: '#gwai710_edit',
                    data: vueData,
                    watch: {
                        /*'form.GWCS117':function () {
                            if(!vueData.form.GWCSDOCDATE){
                                app.showMessage('请先维护订单日期');
                                vueData.form.GWCS117=null;
                            }else {
                                if(vueData.form.GWCS117 && !vueData.isCheck){
                                    self.checkGwcs117()
                                }
                            }

                        },
                        'form.GWCS010':function () {
                            if(!vueData.form.GWCSDOCDATE){
                                app.showMessage('请先维护订单日期');
                                vueData.form.GWCS117=null;
                                vueData.form.GWCS010=null;
                            }else {
                                if(vueData.form.GWCS117 && !vueData.isCheck){
                                    self.checkGwcs117()
                                }
                            }

                        },*/
                        'form.GWCSMLEGAL': function () {
                            var list = gwai710Table.getDatas();
                            for (var i = 0; i < list.length; i++) {
                                list[i].GWCSMLEGAL = vueData.form.GWCSMLEGAL;
                                list[i].GWCSPLANT = vueData.form.GWCSPLANT
                            }
                            gwai710Table.reload({
                                data: list, totalRow: true, toolbar: true
                            });
                        }
                    },
                    methods: {
                        addData: function () {
                            listData = gwai710Table.getDatas();
                            var GWCS112="",
                                GWCS116=0;
                            if (vueData.form.GWCS010 == null || vueData.form.GWCS010 == '') {
                                app.showError('经销商不可为空');
                            }else if (vueData.form.GWCS117 == null || vueData.form.GWCS117 == '') {
                                app.showError('返利类型不可为空');
                            } else {
                                // app.ajax({
                                //     xurl: 'crm/gwai710/getGwdd',
                                //     xdata: {GWCS010: vueData.form.GWCS010,GWCSDOCDATE:vueData.form.GWCSDOCDATE},
                                //     cb: function (result) {
                                //         if(result.data.data.GWDD003=="2"){
                                //             GWCS112="2";
                                //             GWCS116=result.data.data.GWDD013;
                                //         }else {
                                //             GWCS112="1";
                                //             GWCS116=0;
                                //         }

                                        //add by ganjia 2019-01-31--start---
                                        var count = listData.length;
                                        listData.push({
                                            GWCSSEQ: count + 1,
                                            GWCS109:'',
                                            GWDC003:'',
                                            GWCS001: '',
                                            GWAML003: '',
                                            GWAML004: '',
                                            GWCS112:GWCS112,
                                            GWCS116:GWCS116,
                                            GWCS113:'',
                                            GWCS003: '0',
                                            GWCS002: '',
                                            GWCS004: '',
                                            GWCS032: '',
                                            GWCS040: 0,
                                            GWCS005: 0,
                                            // GWCS016: '',
                                            GWCS110: '',
                                            GWCS033: '2',
                                            GWCS034: vueData.form.GWCS034,
                                            GWCS036: 0,
                                            GWCS037: 0,
                                            GWCS038: 0,
                                            GWCS039: 0,
                                            GWCS041: 0,
                                            GWCSMLEGAL: vueData.form.GWCSMLEGAL,
                                            GWCSPLANT: vueData.form.GWCSPLANT,
                                            GWEA006: '',
                                            GWCS035: 1,
                                            GWCS043: '',
                                            GWCS101: ''
                                        });
                                        self.tableReload();
                                        if(listData.length > 0){
                                            vueData.isEnable = true;
                                        }
                                        //add by ganjia 2019-01-31--end---

                            //         }
                            //     });
                            }
                        },
                        cancle: function () {
                            layer.close(layOpenIndex);
                        },
                        del: function () {
                            listData = gwai710Table.getDatas();
                            var checkStatus = table.checkStatus('gwai710_edit_table');
                            if (checkStatus.data.length == 1) {
                                checkStatus.data.forEach(function (v) {
                                    if(v.GWCS111=="1" && (v.GWCS110=="1" || v.GWCS110=="2")){
                                        var GWDC020=0,
                                            GWDC021=0;
                                        var _xData={};
                                            _xData={GWCS109:v.GWCS109,GWCS010:vueData.form.GWCS010};
                                        if(v.GWCS110=="2"){
                                            _xData.GWDC005=v.GWCS110;
                                        }
                                        app.ajax({
                                            xurl: 'crm/gwai710/getGwdc020_021',
                                            xdata: _xData,
                                            async:false,
                                            cb: function (rt) {
                                                if (rt.ok) {
                                                    GWDC020=rt.data.data.GWDC020;
                                                    GWDC021=rt.data.data.GWDC021;
                                                    var GWCS003=0;
                                                    if(v.GWCS111 =="1"){//组合
                                                        listData.forEach(function (item) {
                                                            if(item.GWCS109==v.GWCS109 && item.GWCSSEQ !=v.GWCSSEQ){
                                                                GWCS003=math.add(GWCS003,item.GWCS003);
                                                            }
                                                        })
                                                    }
                                                    if(GWCS003 < GWDC020){
                                                        app.confirm({
                                                            msg: '删除资料导致不满足促销活动，是否确定删除？',
                                                            ok: function () {
                                                                listData.removeByMap({
                                                                    GWCSSEQ: v.GWCSSEQ
                                                                });
                                                                listData.forEach(function (item) {
                                                                    if(v.GWCS109==item.GWCS109){
                                                                        item.GWCS109='';
                                                                        item.GWDC003='';
                                                                        item.GWCS110='';
                                                                        item.GWCS111='';
                                                                        item.GWCS004=item.GWCS115;
                                                                        item.GWCS005=math.mul(item.GWCS003,item.GWCS115);
                                                                        item.GWCS040=math.sub(item.GWCS005,math.div(item.GWCS005,math.add(1,math.div(item.GWEA006,100)))).toFixed(2);
                                                                    }
                                                                });
                                                                self.tableReload();
                                                                listData = gwai710Table.getDatas();
                                                                if(listData.length == 0){
                                                                    vueData.isEnable = false;
                                                                }
                                                            },
                                                            cancel:function () {
                                                            }
                                                        });
                                                    }else {
                                                        listData.removeByMap({
                                                            GWCSSEQ: v.GWCSSEQ
                                                        });
                                                    }
                                                }
                                            }
                                        });
                                    }else {
                                        listData.removeByMap({
                                            GWCSSEQ: v.GWCSSEQ
                                        });
                                    }
                                });
                                self.tableReload();
                            }
                            if (checkStatus.data.length > 1) {
                                var msg='活动编号为：',
                                    GWCS109_TMP=null,
                                    flag=true,
                                    rmData=[],
                                    GWCS109_=[];

                                checkStatus.data.forEach(function (v) {
                                    if(v.GWCS111=="1" && (v.GWCS110=="1" || v.GWCS110=="2") &&(GWCS109_TMP==null ||GWCS109_TMP !=v.GWCS109)){
                                        var GWDC020=0,
                                            GWDC021=0;
                                        var _xData={};
                                        _xData={GWCS109:v.GWCS109,GWCS010:vueData.form.GWCS010};
                                        if(v.GWCS110=="2"){
                                            _xData.GWDC005=v.GWCS110;
                                        }
                                        app.ajax({
                                            xurl: 'crm/gwai710/getGwdc020_021',
                                            xdata: _xData,
                                            async:false,
                                            cb: function (rt) {
                                                if (rt.ok) {
                                                    GWDC020=rt.data.data.GWDC020;
                                                    GWDC021=rt.data.data.GWDC021;
                                                    var GWCS003=0;
                                                    if(v.GWCS111 =="1"){//组合
                                                        listData.forEach(function (item) {
                                                            if(item.GWCS109==v.GWCS109 && item.GWCSSEQ !=v.GWCSSEQ){
                                                                GWCS003=math.add(GWCS003,item.GWCS003);
                                                            }
                                                        })
                                                    }
                                                    if(GWCS003 < GWDC020){
                                                        flag=false;
                                                        msg= msg+v.GWCS109+'、'
                                                        rmData.push(v.GWCSSEQ);
                                                        var tt=v.GWCS109+'/Y';
                                                        GWCS109_.push(tt);
                                                        return;
                                                    }else {
                                                        var tt=v.GWCS109+'/N';
                                                        rmData.push(v.GWCSSEQ);
                                                        GWCS109_.push(tt);
                                                        return;
                                                    }
                                                }
                                            }
                                        });
                                        GWCS109_TMP=v.GWCS109;
                                    }else {
                                        listData.removeByMap({
                                            GWCSSEQ: v.GWCSSEQ
                                        });
                                    }
                                });
                                if(!flag){
                                    app.confirm({
                                        msg: '删除资料导致'+msg+'不满足促销活动，是否确定删除？',
                                        ok: function () {
                                            rmData.forEach(function (r) {
                                                listData.removeByMap({
                                                    GWCSSEQ: r
                                                });
                                            });
                                            GWCS109_.forEach(function (hd) {
                                                var _GWCS109=hd.split('/');
                                                listData.forEach(function (item) {
                                                    if(_GWCS109[0]==item.GWCS109 && _GWCS109[1]=="Y"){
                                                        item.GWCS109='';
                                                        item.GWDC003='';
                                                        item.GWCS110='';
                                                        item.GWCS111='';
                                                        item.GWCS004=item.GWCS115;
                                                        item.GWCS005=math.mul(item.GWCS003,item.GWCS115);
                                                        item.GWCS040=math.sub(item.GWCS005,math.div(item.GWCS005,math.add(1,math.div(item.GWEA006,100)))).toFixed(2);
                                                    }
                                                });
                                            });
                                            self.tableReload();
                                            listData = gwai710Table.getDatas();
                                            if(listData.length == 0){
                                                vueData.isEnable = false;
                                            }

                                        },
                                        cancel:function () {
                                        }
                                    });
                                }
                                self.tableReload();
                            }
                            listData = gwai710Table.getDatas();
                            if(listData.length == 0){
                                vueData.isEnable = false;
                            }
                        },
                        saveData: function () {
                            this.$refs['form'].validate(function (valid) {
                                if (valid) {
                                    listData = gwai710Table.getDatas();
                                    if(listData.length < 1){
                                        app.showWarning('单身商品不可为空!');
                                        return;
                                    }
                                    for (var i = 0; i < listData.length; i++) {
                                        var v = listData[i];
                                        if (v.GWCS001 == '' || v.GWCS001 == null) {
                                            app.showWarning('存在商品为空的资料!');
                                            return;
                                        }
                                        if (v.GWCS113 == '' || v.GWCS113 == null) {
                                            app.showWarning('存在发货仓库为空的资料!');
                                            return;
                                        }
                                        if (v.GWCS003 == '' || v.GWCS003 == null
                                            || v.GWCS003 <=0 ) {
                                            app.showWarning('存在数量小于等于0的资料!');
                                            return;
                                        }
                                        var sum_gwcs003=0;
                                        var sum_gwcs005=0;
                                        listData.forEach(function (item) {
                                            //组合+满量
                                            if (v.GWCS109 == item.GWCS109 && v.GWCS110 == "4" && v.GWCS111 == "1") {
                                                sum_gwcs003 = math.add(sum_gwcs003, item.GWCS003);
                                            }
                                            //组合+满额
                                            if (v.GWCS109 == item.GWCS109 && v.GWCS110 == "3" && v.GWCS111 == "1") {
                                                sum_gwcs005 = math.add(sum_gwcs005, item.GWCS005);

                                            }
                                            //组合+裸价
                                            if (v.GWCS109 == item.GWCS109 && v.GWCS110 == "1" && v.GWCS111 == "1") {
                                                sum_gwcs005 = math.add(sum_gwcs005, item.GWCS005);

                                            }
                                            //非组合+满量
                                            if(v.GWCS109==item.GWCS109 && v.GWCS110=="4" && v.GWCS111=="2" && v.GWCSSEQ==item.GWCSSEQ){
                                                sum_gwcs003=math.add(sum_gwcs003,item.GWCS003);
                                            }
                                            //非组合+满额
                                            if(v.GWCS109==item.GWCS109 && v.GWCS110=="3" && v.GWCS111=="2" && v.GWCSSEQ==item.GWCSSEQ){
                                                sum_gwcs005=math.add(sum_gwcs005,item.GWCS005);
                                            }
                                            //非组合+裸价
                                            if(v.GWCS109==item.GWCS109 && v.GWCS110=="1" && v.GWCS111=="2" && v.GWCSSEQ==item.GWCSSEQ){
                                                sum_gwcs005=math.add(sum_gwcs005,item.GWCS005);
                                            }

                                        });
                                        var flag=true;
                                        //组合+满量
                                        if (v.GWCS110 == "4" && v.GWCS111 == "1") {
                                            app.ajax({
                                                xurl: 'crm/gwai710/getGwcsz005_006',
                                                xdata: {GWCS109:v.GWCS109,GWCSDOCNO:vueData.form.GWCSDOCNO,GWCS010:vueData.form.GWCS010,sum_gwcs003:sum_gwcs003},
                                                async:false,
                                                cb: function (result) {
                                                    if(result.ok){
                                                        listData=gwai710Table.getDatas();
                                                        var GWDC020=0,GWDC021=0,GWDC025=0,GWDC026=0;
                                                        //首先判断订单单身是否满足起订数量
                                                        if(sum_gwcs003 < result.data.data.GWDC020){
                                                            var msg='订单总数量不满足活动起订数量：'+result.data.data.GWDC020;
                                                            app.showWarning(msg);
                                                            flag=false;
                                                            return;
                                                        }

                                                        //如果活动设置的是最大可赠送金额
                                                        if(result.data.data.GWDC025 > 0 && result.data.data.GWCSZ006 >0){
                                                            if(math.mul(parseInt(math.div(sum_gwcs003,result.data.data.GWDC020)),result.data.data.GWDC025) < result.data.data.GWCSZ006){
                                                                var msg='活动编号:'+v.GWCS109+'，赠品信息超过促销活动里最大可赠金额，请重新维护赠品信息或商品数量！';
                                                                app.showWarning(msg);
                                                                flag=false;
                                                                return;
                                                            }
                                                        }
                                                        //如果活动设置的是最大可赠送数量
                                                        if(result.data.data.GWDC026 > 0 && result.data.data.GWCSZ005 >0){
                                                            if(math.mul(parseInt(math.div(sum_gwcs003,result.data.data.GWDC020)),result.data.data.GWDC026) < result.data.data.GWCSZ005){
                                                                var msg='活动编号:'+v.GWCS109+'，赠品信息超过促销活动里最大可赠数量，请重新维护赠品信息或商品数量！';
                                                                app.showWarning(msg);
                                                                flag=false;
                                                                return;
                                                            }
                                                        }

                                                    }
                                                }
                                            });
                                        }
                                        //组合+满额
                                        if (v.GWCS110 == "3" && v.GWCS111 == "1") {
                                            app.ajax({
                                                xurl: 'crm/gwai710/getGwcsz005_006',
                                                xdata: {GWCS109:v.GWCS109,GWCSDOCNO:vueData.form.GWCSDOCNO,GWCS010:vueData.form.GWCS010,sum_gwcs005:sum_gwcs005},
                                                async:false,
                                                cb: function (result) {
                                                    if(result.ok){
                                                        //首先判断单身是否满足起订金额
                                                        if(sum_gwcs005 < result.data.data.GWDC021){
                                                            var msg='订单总金额不满足活动起订金额：'+result.data.data.GWDC021;
                                                            app.showWarning(msg);
                                                            flag=false;
                                                            return;
                                                        }
                                                        //如果活动设置的是最大赠送金额
                                                        if(result.data.data.GWDC025 > 0 && result.data.data.GWCSZ006 >0){
                                                            if(math.mul(parseInt(math.div(sum_gwcs005,result.data.data.GWDC021)),result.data.data.GWDC025) < result.data.data.GWCSZ006){
                                                                var msg='活动编号:'+v.GWCS109+'，赠品信息超过促销活动里最大可赠金额，请重新维护赠品信息或商品数量！';
                                                                app.showWarning(msg);
                                                                flag=false;
                                                                return;
                                                            }
                                                        }
                                                        //如果活动设置的是最大赠送数量
                                                        if(result.data.data.GWDC026 > 0 && result.data.data.GWCSZ005 >0){
                                                            if(math.mul(parseInt(math.div(sum_gwcs005,result.data.data.GWDC021)),result.data.data.GWDC026) < result.data.data.GWCSZ005){
                                                                var msg='活动编号:'+v.GWCS109+'，赠品信息超过促销活动里最大可赠数量，请重新维护赠品信息或商品数量！';
                                                                app.showWarning(msg);
                                                                flag=false;
                                                                return;
                                                            }
                                                        }

                                                    }
                                                }
                                            });
                                        }
                                        //非组合+满量
                                        if (v.GWCS110 == "4" && v.GWCS111 == "2") {
                                            app.ajax({
                                                xurl: 'crm/gwai710/getGwcsz005_006',
                                                xdata: {GWCS109:v.GWCS109,GWCSDOCNO:vueData.form.GWCSDOCNO,GWCS001:v.GWCS001,GWCS010:vueData.form.GWCS010,sum_gwcs003:sum_gwcs003},
                                                async:false,
                                                cb: function (result) {
                                                    if(result.ok){
                                                        listData=gwai710Table.getDatas();
                                                        var GWDC020=0,GWDC021=0,GWDC025=0,GWDC026=0;
                                                        //首先判断订单单身是否满足起订数量
                                                        if(sum_gwcs003 < result.data.data.GWDC020){
                                                            var msg='活动编号：'+v.GWCS109+'产品：'+v.GWCS001+',数量不满足活动起订数量：'+result.data.data.GWDC020;
                                                            app.showWarning(msg);
                                                            flag=false;
                                                            return;
                                                        }
                                                        //如果活动设置的是最大可赠送金额
                                                        if(result.data.data.GWDC025 > 0 && result.data.data.GWCSZ006 >0){
                                                            if(math.mul(parseInt(math.div(sum_gwcs003,result.data.data.GWDC020)),result.data.data.GWDC025) < result.data.data.GWCSZ006){
                                                                var msg='活动编号:'+v.GWCS109+'，赠品信息超过促销活动里最大可赠金额，请重新维护赠品信息或商品数量！';
                                                                app.showWarning(msg);
                                                                flag=false;
                                                                return;
                                                            }
                                                        }
                                                        //如果活动设置的是最大可赠送数量
                                                        if(result.data.data.GWDC026 > 0 && result.data.data.GWCSZ005 >0){
                                                            if(math.mul(parseInt(math.div(sum_gwcs003,result.data.data.GWDC020)),result.data.data.GWDC026) < result.data.data.GWCSZ005){
                                                                var msg='活动编号:'+v.GWCS109+'，赠品信息超过促销活动里最大可赠数量，请重新维护赠品信息或商品数量！';
                                                                app.showWarning(msg);
                                                                flag=false;
                                                                return;
                                                            }
                                                        }

                                                    }
                                                }
                                            });
                                        }
                                        //非组合+满额
                                        if (v.GWCS110 == "3" && v.GWCS111 == "2") {
                                            app.ajax({
                                                xurl: 'crm/gwai710/getGwcsz005_006',
                                                xdata: {GWCS109:v.GWCS109,GWCSDOCNO:vueData.form.GWCSDOCNO,GWCS001:v.GWCS001,GWCS010:vueData.form.GWCS010,sum_gwcs005:sum_gwcs005},
                                                async:false,
                                                cb: function (result) {
                                                    if(result.ok){
                                                        //首先判断单身是否满足起订金额
                                                        if(sum_gwcs005 < result.data.data.GWDC021){
                                                            var msg='活动编号：'+v.GWCS109+'产品：'+v.GWCS001+',金额不满足活动起订金额：'+result.data.data.GWDC021;
                                                            app.showWarning(msg);
                                                            flag=false;
                                                            return;
                                                        }
                                                        //如果活动设置的是最大可赠送金额
                                                        if(result.data.data.GWDC025 > 0 && result.data.data.GWCSZ006 >0){
                                                            if(math.mul(parseInt(math.div(sum_gwcs005,result.data.data.GWDC021)),result.data.data.GWDC025) < result.data.data.GWCSZ006){
                                                                var msg='活动编号:'+v.GWCS109+'，赠品信息超过促销活动里最大可赠金额，请重新维护赠品信息或商品数量！';
                                                                app.showWarning(msg);
                                                                flag=false;
                                                                return;
                                                            }
                                                        }
                                                        //如果活动设置的是最大可赠送数量
                                                        if(result.data.data.GWDC026 > 0 && result.data.data.GWCSZ005 >0){
                                                            if(math.mul(parseInt(math.div(sum_gwcs005,result.data.data.GWDC021)),result.data.data.GWDC026) < result.data.data.GWCSZ005){
                                                                var msg='活动编号:'+v.GWCS109+'，赠品信息超过促销活动里最大可赠数量，请重新维护赠品信息或商品数量！';
                                                                app.showWarning(msg);
                                                                flag=false;
                                                                return;
                                                            }
                                                        }

                                                    }
                                                }
                                            });
                                        }

                                        //组合+裸价
                                        if (v.GWCS110 == "1" && v.GWCS111 == "1"){
                                            app.ajax({
                                                xurl: 'crm/gwai710/getGwdc020_021',
                                                xdata: {GWCS109:v.GWCS109,GWCS010:vueData.form.GWCS010,sum_gwcs005:sum_gwcs005},
                                                async:false,
                                                cb: function (result) {
                                                    if(result.ok){
                                                        //首先判断单身是否满足起订金额
                                                        if(sum_gwcs005 < result.data.data.GWDC021){
                                                            var msg='组合活动编号:'+v.GWCS109+',总金额不满足活动起订金额：'+result.data.data.GWDC021;
                                                            app.showWarning(msg);
                                                            flag=false;
                                                            return;
                                                        }
                                                    }
                                                }
                                            });
                                        }
                                        //非组合+裸价
                                        if (v.GWCS110 == "1" && v.GWCS111 == "2"){
                                            app.ajax({
                                                xurl: 'crm/gwai710/getGwdc020_021',
                                                xdata: {GWCS109:v.GWCS109,GWCS010:vueData.form.GWCS010,GWCS001:v.GWCS001,sum_gwcs005:sum_gwcs005},
                                                async:false,
                                                cb: function (result) {
                                                    if(result.ok){
                                                        //首先判断单身是否满足起订金额
                                                        if(sum_gwcs005 < result.data.data.GWDC021){
                                                            var msg='非组合活动编号:'+v.GWCS109+',产品编号:'+v.GWCS001+',总金额不满足活动起订金额：'+result.data.data.GWDC021;
                                                            app.showWarning(msg);
                                                            flag=false;
                                                            return;
                                                        }
                                                    }
                                                }
                                            });
                                        }

                                        if(!flag){
                                           return;
                                        }
                                    }
                                    listData.addMap(vueData.form, false);
                                    if(flag){
                                        if (vueData.isAdd) {
                                            self.addData(listData);
                                        } else {
                                            self.editData(listData);
                                        }
                                    }

                                }
                            });
                        },
                        deleteDataBatch: function () {

                            app.confirm({
                                msg: '是否删除选择的数据？',
                                ok: function () {
                                    self.deleteDataBatch();
                                }
                            });
                        },
                        openKh: function () {
                            var list = gwai710Table.getDatas();
                            if (list.length > 0) {
                                app.confirm({
                                    msg: '是否修改客户？',
                                    ok: function () {
                                        vueData.form.GWCS010 = '';
                                        vueData.form.GWAKL003 = '';
                                        listData = [];
                                        self.tableReload();
                                        vueData.isEnable = false;
                                        self._openTplFull({
                                            tag: 'common_open_window',
                                            tagData: {
                                                config: {
                                                    method:'cq_gwak001_4',
                                                    columnList: [
                                                        {label: '客户编号', prop: 'GWAK001', width: '150'},
                                                        {label: '客户简称', prop: 'GWAKL003', width: '150'},
                                                        {label: '客户全称', prop: 'GWAKL004', width: '150'}
                                                    ]
                                                },
                                                cb: function (data) {
                                                    vueData.form.GWCS010 = data.GWAK001;
                                                    vueData.form.GWAKL003 = data.GWAKL003;
                                                    app.ajax({
                                                        xurl: 'crm/gwai710/getGwcs034',
                                                        xdata: {GWAK001: data.GWAK001},
                                                        cb: function (result) {
                                                            vueData.form.GWCS033 = result.data.data.GWCS033;//汇率类型
                                                            vueData.form.GWCS034 = result.data.data.GWCS034;//汇率
                                                            vueData.form.GWCS006 = result.data.data.GWCS006;//币种
                                                            vueData.form.GWCSPLANT = result.data.data.GWCSPLANT;
                                                            vueData.form.GWCSMLEGAL = result.data.data.GWCSMLEGAL;
                                                            vueData.form.GWCSMLEGAL_NAME = result.data.data.GWCSMLEGAL_NAME;
                                                            vueData.form.GWCS118 = 'N';//拆包否
                                                            if(result.data.data.GWCS118=='Y'){
                                                                vueData.isChange=false;
                                                            }else {
                                                                vueData.isChange=true;
                                                            }
                                                        }
                                                    });
                                                    /*app.ajax({
                                                     xurl: 'crm/gwai710/getGwcs035',
                                                     xdata: {GWAK001: data.GWAK001},
                                                     cb: function (result) {
                                                     vueData.form.GWCS035 = result.data.data.GWCS035;
                                                     }
                                                     });*/
                                                },
                                            },
                                            index: 0,
                                            openOpts: {
                                                title: '选择客户信息',
                                                area: ['600px', '470px']
                                            }
                                        });
                                    }
                                });
                            } else {
                                self._openTplFull({
                                    tag: 'common_open_window',
                                    tagData: {
                                        config: {
                                            method:'cq_gwak001_4',
                                            columnList: [
                                                {label: '客户编号', prop: 'GWAK001', width: '150'},
                                                {label: '客户简称', prop: 'GWAKL003', width: '150'},
                                                {label: '客户全称', prop: 'GWAKL004', width: '150'}
                                            ]
                                        },
                                        cb: function (data) {
                                            vueData.form.GWCS010 = data.GWAK001;
                                            vueData.form.GWAKL003 = data.GWAKL003;
                                            app.ajax({
                                                xurl: 'crm/gwai710/getGwcs034',
                                                xdata: {GWAK001: data.GWAK001},
                                                cb: function (result) {
                                                    vueData.form.GWCS033 = result.data.data.GWCS033;//汇率类型
                                                    vueData.form.GWCS034 = result.data.data.GWCS034;//汇率
                                                    vueData.form.GWCS006 = result.data.data.GWCS006;//币种
                                                    vueData.form.GWCSPLANT = result.data.data.GWCSPLANT;
                                                    vueData.form.GWCSMLEGAL = result.data.data.GWCSMLEGAL;
                                                    vueData.form.GWCSMLEGAL_NAME = result.data.data.GWCSMLEGAL_NAME;
                                                    vueData.form.GWCS118 = 'N';//拆包否
                                                    if(result.data.data.GWCS118=='Y'){
                                                        vueData.isChange=false;
                                                    }else {
                                                        vueData.isChange=true;
                                                    }
                                                }
                                            });
                                            /*app.ajax({
                                             xurl: 'crm/gwai710/getGwcs035',
                                             xdata: {GWAK001: data.GWAK001},
                                             cb: function (result) {
                                             vueData.form.GWCS035 = result.data.data.GWCS035;
                                             }
                                             });*/
                                        },
                                    },
                                    index: 0,
                                    openOpts: {
                                        title: '选择客户信息',
                                        area: ['600px', '470px']
                                    }
                                });
                            }
                        },
                        /*openJxs: function () {
                            self._openTplFull({
                                tag: 'common_open_kh',
                                tagData: {
                                    cb: function (data) {
                                        vueData.form.GWCS011 = data.GWAK001;
                                    }
                                },
                                index: 2,
                                openOpts: {
                                    title: '选择经销商信息',
                                    area: ['600px', '430px']
                                }
                            });
                        },*/
                        open: function () {
                            self._openTplFull({
                                tag: 'common_open_window',
                                tagData: {
                                    config: {
                                        method:'cq_sysorg_biz_2',
                                        columnList: [
                                            {label: '组织编号', prop: 'ID', width: '150'},
                                            {label: '组织名称', prop: 'NAME', width: '150'},
                                            {label: '营运中心编号', prop: 'AZP01', width: '150'},
                                            {label: '营运中心名称', prop: 'AZP02', width: '150'}
                                        ]
                                    },
                                    cb: function (data) {
                                        vueData.form.GWCSMLEGAL = data.ID;
                                        vueData.form.GWCSMLEGAL_NAME = data.NAME;
                                        vueData.form.GWCSPLANT = data.AZP01;
                                    },
                                },
                                index: 0,
                                openOpts: {
                                    title: '选择归属法人信息',
                                    area: ['600px', '470px']
                                }
                            });
                        },
                        openUser: function () {
                            self._openTplFull({
                                tag: 'common_open_window',
                                tagData: {
                                    config: {
                                        method:'q_sysuser_id',
                                        columnList: [
                                            {label: '人员编号', prop: 'ID', width: '150'},
                                            {label: '姓名', prop: 'NAME', width: '150'},
                                            {label: '账户', prop: 'ACCOUNT', width: '150'}
                                        ]
                                    },
                                    cb: function (data) {
                                        vueData.form.GWCS014 = data.ID;
                                        vueData.form.GWCS014_NAME = data.ACCOUNT+"("+data.NAME+")";
                                    },
                                },
                                index: 0,
                                openOpts: {
                                    title: '选择销售人员信息',
                                    area: ['600px', '470px']
                                }
                            });
                        },
                        check: function () {
                            var flag = true;
                            var list = gwai710Table.getDatas();
                            var _xdata = [];
                            list.forEach(function (v) {
                                var _temp = app.fields_('GWCS');
                                if (v.GWCSACTI != 'N') {
                                    app.showWarning("只有状态为N：未审核的正式订单才可以审核！");
                                    flag = false;
                                    return;
                                } else {
                                    _temp.GWCSENT = v.GWCSENT;
                                    _temp.GWCSDOCNO = v.GWCSDOCNO;
                                    _temp.GWCSACTI = "Y";
                                    v.GWCSACTI = "Y";
                                    _xdata.push(_temp);
                                }
                            });
                            if (flag) {
                                app.confirm({
                                    msg: '是否审核选择的数据？',
                                    ok: function () {
                                        app.ajax({
                                            xurl: 'crm/gwai710/updateData',
                                            xdata: _xdata,
                                            toJsonStr: true,
                                            okmsg: '正式订单审核成功',
                                            cb: function (result) {
                                                if (result.ok) {
                                                    listData = list;
                                                    self.tableReload();
                                                    app.pageModule('gwai710').reloadTableCurr();
                                                }
                                            }
                                        });
                                    }
                                });
                            }
                        },
                        uncheck: function () {
                            var flag = true;
                            var list = gwai710Table.getDatas();
                            var _xdata = [];
                            list.forEach(function (v) {
                                var _temp = app.fields_('GWCS');
                                if (v.GWCSACTI != 'Y') {
                                    app.showWarning("只有状态为Y：已审核的正式订单才可以取消审核！");
                                    flag = false;
                                    return;
                                } else {
                                    _temp.GWCSENT = v.GWCSENT;
                                    _temp.GWCSDOCNO = v.GWCSDOCNO;
                                    _temp.GWCSACTI = "N";
                                    v.GWCSACTI = "N";
                                    _xdata.push(_temp);
                                }
                            });
                            if (flag) {
                                app.confirm({
                                    msg: '是否取消审核选择的数据？',
                                    ok: function () {
                                        app.ajax({
                                            xurl: 'crm/gwai710/updateData',
                                            xdata: _xdata,
                                            toJsonStr: true,
                                            okmsg: '正式订单取消审核成功',
                                            cb: function (result) {
                                                if (result.ok) {
                                                    listData = list;
                                                    self.tableReload();
                                                    app.pageModule('gwai710').reloadTableCurr();
                                                }
                                            }
                                        });
                                    }
                                });
                            }
                        },
                        giftInfo:function () {
                            var giftClick=false;
                            if(vueData.form.GWCSACTI != null && vueData.form.GWCSACTI != '' && vueData.form.GWCSACTI !="T"){
                                giftClick=true;
                            }
                            self._openTplFull({
                                tag: 'gwai710_edit_giftInfo',
                                tagData: {
                                    moduleName:"赠品信息",
                                    GWCSDOCNO:vueData.form.GWCSDOCNO,
                                    GWCS010:vueData.form.GWCS010,
                                    giftClick:giftClick
                                },
                                index: 2,
                                openOpts: {
                                    title: '赠品信息编辑',
                                    maxmin: true
                                }
                            });

                        },
                        editAccess:function () {
                            vueData.giftButton = true;
                            vueData.isAdd = false;
                            vueData.isCheck = false;
                        },
                        change: function (data) {
                            if(vueData.form.GWCSDOCDATE != null) {
                                if (data < vueData.form.GWCSDOCDATE) {
                                    vueData.form.GWCS016 = '';
                                    app.showWarning('预计交货日期不允许小于正式单日期!');
                                }
                            }else{
                                vueData.form.GWCS016 = '';
                                app.showWarning('请先选择正式单日期!');
                            }
                        },
                        changeGwcsdocdate:function (data) {
                            if(vueData.form.GWCSDOCDATE){
                                vueData.form.GWCS117=null;
                            }
                        },
                        editCk:function () {
                            self._openTplFull({
                                tag: 'common_open_window',
                                tagData: {
                                    config: {
                                        method:'q_gwas001',
                                        columnList: [
                                            {label: '仓库编号', prop: 'GWAS001', width: '150'},
                                            {label: '仓库名称', prop: 'GWASL003', width: '150'}
                                        ]
                                    },
                                    cb: function (data) {
                                        app.ajax({
                                            xurl: 'crm/gwai710/updateGWCS113',
                                            xdata: {GWCS113: data.GWAS001,GWCS112:data.GWAS003,
                                                GWCSDOCNO:vueData.form.GWCSDOCNO},
                                            cb: function (result) {
                                                if (result.ok) {
                                                    listData.forEach(function (v) {
                                                        v.GWCS113 = data.GWAS001;
                                                        v.GWCS112 = data.GWAS003;
                                                    });
                                                    self.tableReload();
                                                }
                                            }
                                        });
                                    },
                                },
                                index: 0,
                                openOpts: {
                                    title: '选择仓库信息',
                                    area: ['600px', '470px']
                                }
                            });
                        },
                        clearGwcs014:function () {
                            vueData.form.GWCS014_NAME='';
                        },
                        clearGwcs010:function () {
                            var tableLength = gwai710Table.getDatas().length;
                            if (tableLength > 0) {
                                vueData.form.GWCS010 = '';
                                vueData.form.GWAKL003 = '';
                                listData = [];
                                self.tableReload();
                                vueData.isEnable = false;
                            }else{
                                vueData.form.GWAKL003 = '';
                            }
                        },
                        clearGwcsmlegal:function () {
                            vueData.form.GWCSPLANT='';
                        }
                    },
                    created: function () {
                        self._setEleIsReady('gwai710_edit');
                    }
                });
                self.initTable();
            },
            _lazy: function () {
                this._super();
            },
            checkGwdc020:function (obj) {
                var GWDC020=0,
                    GWDC021=0;
                var _xdata={};
                if(obj.data.GWCS111 =="1"){//组合
                    _xdata= {GWCS109:obj.data.GWCS109,GWCS010:vueData.form.GWCS010};
                }else {
                    _xdata= {GWCS109:obj.data.GWCS109,GWCS001:obj.data.GWCS001,GWCS010:vueData.form.GWCS010};
                }
                app.ajax({
                    xurl: 'crm/gwai710/getGwdc020_021',
                    xdata: _xdata,
                    async:false,
                    cb: function (rt) {
                        if (rt.ok) {
                            GWDC020=rt.data.data.GWDC020;
                            GWDC021=rt.data.data.GWDC021;
                            var GWCS003=0;
                            listData.forEach(function (item) {
                                if(item.GWCS109==obj.data.GWCS109 && item.GWCSSEQ !=obj.data.GWCSSEQ){
                                    GWCS003=math.add(GWCS003,item.GWCS003);
                                }
                            })
                            GWCS003=math.add(GWCS003,obj.value);
                            if(GWCS003 < GWDC020){
                                var _data={};
                                if(obj.data.GWCS111=="1"){//组合
                                    _data={GWCSDOCNO:vueData.form.GWCSDOCNO,GWCS109:obj.data.GWCS109};
                                }
                                if(obj.data.GWCS111=="2"){//非组合
                                    _data={GWCSDOCNO:vueData.form.GWCSDOCNO,GWCS109:obj.data.GWCS109,GWCS001:obj.data.GWCS001};
                                }
                                app.confirm({
                                    msg: '修改数量导致不满足促销活动，是否确定修改？',
                                    ok: function () {
                                        //确定修改后会清除所有与活动有关的信息，包括赠品信息
                                        app.ajax({
                                            xurl: 'crm/gwai710/delGwcszByGwcsz007',
                                            xdata: _data,
                                            cb: function (rt) {
                                                if (rt.ok) {
                                                    layer.msg('赠品信息清除成功');
                                                }
                                            }
                                        });
                                        //先调整当前行
                                        var hs=math.mul(obj.value,obj.data.GWCS115);
                                        obj.updateOfEdit({
                                            'GWCS003':obj.value,
                                            'GWCS109': '',
                                            'GWDC003': '',
                                            'GWCS110': '',
                                            'GWCS111': '',
                                            'GWCS004':obj.data.GWCS115,
                                            'GWCS040':math.sub(hs,math.div(hs,math.add(1,math.div(obj.data.GWEA006,100)))).toFixed(2),
                                            'GWCS005':math.mul(obj.value,obj.data.GWCS115)
                                        });
                                        listData=gwai710Table.getDatas();
                                        //再调整其他行
                                        if(obj.data.GWCS111=="1"){//组合
                                            listData.forEach(function (item) {
                                                if(obj.data.GWCS109==item.GWCS109){
                                                    item.GWCS109='';
                                                    item.GWDC003='';
                                                    item.GWCS110='';
                                                    item.GWCS111='';
                                                    item.GWCS004=item.GWCS115;
                                                    item.GWCS005=math.mul(item.GWCS003,item.GWCS115);
                                                    item.GWCS040=math.sub(item.GWCS005,math.div(item.GWCS005,math.add(1,math.div(item.GWEA006,100)))).toFixed(2);
                                                }
                                            });
                                        }
                                        // listData=gwai710Table.getDatas();
                                        self.tableReload();
                                    },
                                    cancel:function () {
                                        // listData=gwai710Table.getDatas();
                                        obj.value=listData[obj.index].GWCS003;
                                        obj.updateOfEdit({
                                            'GWCS003':obj.value
                                        });
                                        self.tableReload();
                                    }
                                });
                            }else {
                                    var hs=math.mul(obj.value,obj.data.GWCS004);
                                    obj.updateOfEdit({
                                        'GWCS003':obj.value,
                                        'GWCS004':obj.data.GWCS004,
                                        'GWCS040':math.sub(hs,math.div(hs,math.add(1,math.div(obj.data.GWEA006,100)))).toFixed(2),
                                        'GWCS005':math.mul(obj.value,obj.data.GWCS004)
                                    });
                                    listData=gwai710Table.getDatas();
                                    self.tableReload();

                            }
                        }
                    }
                });

            },
            checkGwdc021:function (obj) {
                var GWDC020=0,
                    GWDC021=0;
                app.ajax({
                    xurl: 'crm/gwai710/getGwdc020_021',
                    xdata: {GWCS109:obj.data.GWCS109,GWCS010:vueData.form.GWCS010},
                    async:false,
                    cb: function (rt) {
                        if (rt.ok) {
                            GWDC020=rt.data.data.GWDC020;
                            GWDC021=rt.data.data.GWDC021;
                            var GWCS005=0;
                            listData.forEach(function (item) {
                                if(item.GWCS109==obj.data.GWCS109 && item.GWCSSEQ !=obj.data.GWCSSEQ){
                                    GWCS005=math.add(GWCS005,item.GWCS005);
                                }
                            })
                            GWCS005=math.add(GWCS005,math.mul(obj.value,obj.data.GWCS004));
                            if(GWCS005 < GWDC021){
                                var _data={};
                                if(obj.data.GWCS111=="1"){//组合
                                    _data={GWCSDOCNO:vueData.form.GWCSDOCNO,GWCS109:obj.data.GWCS109};
                                }
                                if(obj.data.GWCS111=="2"){//非组合
                                    _data={GWCSDOCNO:vueData.form.GWCSDOCNO,GWCS109:obj.data.GWCS109,GWCS001:obj.data.GWCS001};
                                }
                                var msg_="起订金额为："+GWDC021+",修改数量导致不满足促销活动，是否确定修改？";
                                app.confirm({
                                    msg: msg_,
                                    ok: function () {
                                        //确定修改后会清除所有与活动有关的信息，包括赠品信息
                                        app.ajax({
                                            xurl: 'crm/gwai710/delGwcszByGwcsz007',
                                            xdata: _data,
                                            cb: function (rt) {
                                                if (rt.ok) {
                                                    layer.msg('赠品信息清除成功');
                                                }
                                            }
                                        });
                                        //先调整当前行
                                        var hs=math.mul(obj.value,obj.data.GWCS115);
                                        obj.updateOfEdit({
                                            'GWCS003':obj.value,
                                            'GWCS109': '',
                                            'GWDC003': '',
                                            'GWCS110': '',
                                            'GWCS111': '',
                                            'GWCS004':obj.data.GWCS115,
                                            'GWCS040':math.sub(hs,math.div(hs,math.add(1,math.div(obj.data.GWEA006,100)))).toFixed(2),
                                            'GWCS005':math.mul(obj.value,obj.data.GWCS115)
                                        });
                                        //再调整其他行
                                        listData.forEach(function (item) {
                                            if(obj.data.GWCS109==item.GWCS109 && obj.data.GWCSSEQ !=item.GWCSSEQ){
                                                item.GWCS109='';
                                                item.GWDC003='';
                                                item.GWCS110='';
                                                item.GWCS111='';
                                                item.GWCS004=item.GWCS115;
                                                item.GWCS005=math.mul(item.GWCS003,item.GWCS115);
                                                item.GWCS040=math.sub(item.GWCS005,math.div(item.GWCS005,math.add(1,math.div(item.GWEA006,100)))).toFixed(2);
                                            }
                                        });
                                        self.tableReload();
                                    },
                                    cancel:function () {
                                        // listData=gwai710Table.getDatas();
                                        obj.value=listData[obj.index].GWCS003;
                                        obj.updateOfEdit({
                                            'GWCS003':obj.value
                                        });
                                        self.tableReload();
                                    }
                                });
                            }else {
                                var hs=math.mul(obj.value,obj.data.GWCS004);
                                obj.updateOfEdit({
                                    'GWCS003':obj.value,
                                    'GWCS004':obj.data.GWCS004,
                                    'GWCS040':math.sub(hs,math.div(hs,math.add(1,math.div(obj.data.GWEA006,100)))).toFixed(2),
                                    'GWCS005':math.mul(obj.value,obj.data.GWCS004)
                                });
                                listData=gwai710Table.getDatas();
                                self.tableReload();
                            }
                        }
                    }
                });
            },
            checkGwcs117:function () {
                app.ajax({
                    xurl: 'crm/gwai710/checkGwcs117',
                    xdata: {GWCSDOCDATE: vueData.form.GWCSDOCDATE,GWCS117: vueData.form.GWCS117,GWCS010:vueData.form.GWCS010},
                    async:false,
                    cb: function (result) {
                        if(result.data.data.num <1){
                            app.showError('合同协议档中没有与此对应的返利编号');
                            vueData.form.GWCS117=null;
                        }
                    }
                });
            }
        });

    return new Gwai710Edit();

});
